const express = require('express')
const path = require('path')

const app = express()

// 设置跨域问题解决方案
// app.all('*', function (req, res, next) {

//     res.setHeader("Access-Control-Allow-Origin", "*");
//         res.header("Access-Control-Allow-Origin", "*");
//         res.header("Access-Control-Allow-Headers", "X-Requested-With");
//         res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
//         res.header("X-Powered-By", ' 3.2.1')
//         res.header("Content-Type", "application/json;charset=utf-8");
//     next();

// });



// 设置静态资源访问路径服务
app.use(express.static(path.join(__dirname,'public')))

app.get('/searchAutoPrompt',(req,res)=>{
    const reg = /jo|jw|wok|joy/
    if(reg.test(req.query.key)){
        res.send(['Joywok1','Joywok2','Joywok3','JoywokJoywok'])
    }else{
        res.send(req.query.key)
    }
})

// 创建路由
app.get('/verifyEamilAdress',(req,res)=>{
    res.send('恭喜！邮箱：'+req.query.email+'注册成功！')
})

// 监听端口
app.listen(3000)
console.log('服务器启动成功！')